<?php
	$slbCategory	= $this->formSelect('id_cate',$this->Item['id_cate'],array(), $this->slbCategory);
?>
<fieldset class="adminField">
	<legend>Bộ lọc</legend>
	<div class="fieldContent">
		<table>
			<tr>
				<td>
					<div class="label">Chọn nhóm</div>
					<?php echo $slbCategory;?>
				</td>
			</tr>
		</table>
	</div>
</fieldset>
<div class="contentPopup">
	<div class="left">
		<fieldset class="adminField">
			<legend>Danh sách</legend>
			<div id="loadMarketing"></div>
			<script type="text/javascript">
				$('#loadMarketing').css({'height': '200px;'}).addClass('dangtai2').load('<?php echo $this->baseUrl('marketing/ajax/load-marketing');?>', function(){ $(this).removeClass('dangtai2'); });

				function chonMarketing(idMarketing, name, ngaybatdau, ngayketthuc){
					if($('#tblDaChon tr#' + idMarketing).length > 0){
						alert('Chiến dịch marketing này đã được chọn');
					}else{
						if($('#tblDaChon tr').length > 0){
							$('#tblDaChon tr:last').after('<tr id="'+idMarketing+'"><td id="name"><a href="javascript:coid(0)" title="'+ ngayketthuc + ' - ' + ngaybatdau +'">' + name + '</td><td align="center"><a href="javascript:void(0)" onclick="xoaChonMarketing('+idMarketing+')">Xóa</a></td></tr>');
						}else{
							$('#tblDaChon').append('<tr><th>Tên chiến dịch</th><th style="text-align: center;"><a href="javascript:void(0)" onclick="xoaChonMarketingAll()">Xóa tất cả</a></th></tr>');
							$('#tblDaChon tr:last').after('<tr id="'+idMarketing+'"><td id="name"><a href="javascript:coid(0)" title="'+ ngayketthuc + ' - ' + ngaybatdau +'">' + name + '</td><td align="center"><a href="javascript:void(0)" onclick="xoaChonMarketing('+idMarketing+')">Xóa</a></td></tr>');
						}
					}
				}

				function chonMarketingAll(){
					if($('#tblDaChon tr').length <= 0){
						$('#tblDaChon').append('<tr><th>Tên chiến dịch</th><th style="text-align: center;"><a href="javascript:void(0)" onclick="xoaChonMarketingAll()">Xóa tất cả</a></th></tr>');
						$('#tableListMarketing tr').each(function(index){
							if(index > 0){
								$('#tblDaChon tr:last').after('<tr id="'+$(this).attr('id')+'"><td id="name"><a href="javascript:coid(0)" title="'+ $('#ngayketthuc', this).text() + ' - ' + $('#ngaybatdau', this).text() +'">' + $('#name', this).text() + '</td><td align="center"><a href="javascript:void(0)" onclick="xoaChonMarketing('+$(this).attr('id')+')">Xóa</a></td></tr>');
							}
						});
					}else{
						$('#tableListMarketing tr').each(function(index){
							if(index > 0){
								//alert($(this).attr('id'));
								if($('#tblDaChon tr#' + $(this).attr('id')).length <= 0){
									$('#tblDaChon tr:last').after('<tr id="'+$(this).attr('id')+'"><td id="name"><a href="javascript:coid(0)" title="'+ $('#ngayketthuc', this).text() + ' - ' + $('#ngaybatdau', this).text() +'">' + $('#name', this).text() + '</td><td align="center"><a href="javascript:void(0)" onclick="xoaChonMarketing('+$(this).attr('id')+')">Xóa</a></td></tr>');
								}
							}
						});
					}
				}

				function xoaChonMarketing(idMarketing){
					$('#tblDaChon tr#' + idMarketing).remove();
					if($('#tblDaChon tr').length == 1){
						$('#tblDaChon tr').remove();
					}
				}

				function xoaChonMarketingAll(){
					$('#tblDaChon tr').remove();
				}
			</script>
		</fieldset>
	</div>
	<div class="right">
		<fieldset class="adminField">
			<legend>Danh sách đã chọn</legend>
			<div style="height: 372px; overflow: auto;">
				<table class="tableTeam1" id="tblDaChon"></table>
			</div>
		</fieldset>
	</div>
</div>